Importing all necessary libraries¶
In [1]:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import plotly.express as px
import plotly.io as pio
pio.renderers.default = 'notebook'
Loading the Data¶
In [2]:
pesticides=pd.read_csv('pesticides.csv')
yield_df=pd.read_csv('yield_df.csv')
Exploratory Data Analysis¶
Top ten Countries which used the highest amount of pesticides in the year of 2016¶
In [3]:
ten_pesticides_country=pesticides[pesticides.Year==2016][['Area','Value']].sort_values(by='Value',ascending=False).head(10)
In [4]:
fig=px.bar(ten_pesticides_country,
y='Area',
x='Value',
title='Top ten countrues which used the highest amount of pesticides in 2016',
color=ten_pesticides_country.Area)
fig.update_layout(
yaxis_title='Country',
xaxis_title='Tonnes of active ingredients',
width=1200,
height=600
)
fig.show()
In [5]:
pesticides_china=pesticides[pesticides.Area.isin(['China, Hong Kong SAR', 'China, Macao SAR','China, mainland', 'China, Taiwan Province of'])][['Area','Year','Value']]
In [6]:
fig=px.bar(
pesticides_china,
x='Year',
y='Value',
color='Area',
title='Pesticides Usage in China from 1990 to 2016',
)
fig.update_layout(
yaxis_title='Tonnes of active ingredients',
width=1200,
height=600
)
fig.show()
In [7]:
pest_china_other_area=pesticides[pesticides.Area.isin(['China, Hong Kong SAR', 'China, Macao SAR','China'])]
In [8]:
fig=px.bar(
pest_china_other_area,
x='Year',
y='Value',
color='Area',
title='Pesticides usage in China (Hong Kong SAR, Macao SAR)'
)
fig.update_layout(
yaxis_title='Tonnes of Active Ingredients',
width=1200,
height=600
)
fig.show()
In [9]:
pesticides_bd=pesticides[pesticides.Area=='Bangladesh']
In [10]:
fig=px.bar(pesticides_bd,
x='Year',
y='Value',
color='Value',
title='Pesticides Usage in Bangladesh From 1990 to 2016')
fig.update_layout(yaxis_title='Tonnes of active ingredients',
width=1200,
height=600)
fig.show()
In [11]:
yield_df=yield_df.drop(columns='Unnamed: 0',inplace=False,axis=1)
yield_df['hg/ha_yield']=yield_df['hg/ha_yield']/10000
yield_df=yield_df.rename(columns={'hg/ha_yield':'ton/ha_yield'})
yield_bd=yield_df[yield_df.Area=='Bangladesh']
In [12]:
fig=px.line(yield_bd,
x='pesticides_tonnes',
y=yield_bd['ton/ha_yield'],
hover_data=['Year'],
color='Item',
title='Pesticides usage on the yield of some dominent crops in Bangladesh from 1990 to 2013')
fig.update_layout(
yaxis_title='Yield (Tonne/Ha)',
xaxis_title='Pesticides Dose (Tonnes)',
width=1200,
height=700
)
fig.show()
Pesticides usage and yield of Rice in Bangladesh from 1990 to 2013¶
In [13]:
yield_bd_rice=yield_bd[yield_bd.Item=='Rice, paddy']
In [14]:
fig=px.line(yield_bd_rice,
x='pesticides_tonnes',
y='ton/ha_yield',
title='Effects of pesticides usage on Rice yield in Bangladesh from 1990 to 2013',
hover_data=['Year']
)
fig.update_layout(
yaxis_title='Yield (Tonne/Ha)',
xaxis_title='Pesticides Dose (Tonnes)',
width=1200,
height=600
)
fig.show()
Both the yield of crops and pesticides application from 2008 to 2012 was uneven¶
In [15]:
yield_8_9_10_11_12=yield_df[yield_df.Year.isin(range(2008,2013))]
yield_8_9_10_11_12_bd=yield_8_9_10_11_12[yield_8_9_10_11_12.Area=='Bangladesh']
yield_pests_8to12=yield_8_9_10_11_12_bd.groupby('Year')[['ton/ha_yield','pesticides_tonnes']].sum()
In [16]:
fig=px.bar(yield_pests_8to12,y='pesticides_tonnes',
x=yield_pests_8to12.index,
title='Pesticides usage and yield of crops from 2008 to 20012',
color='ton/ha_yield'
)
fig.update_layout(
yaxis_title='Pesticides Dose (Tonnes)',
xaxis_title='Year',
width=1200,
height=600
)
fig.show()
In [17]:
yield_2000to2007=yield_df[yield_df.Year.isin([2000,2001,2002,2004,2005,2006,2007])]
yield_2000to2007bd=yield_2000to2007[yield_2000to2007.Area=='Bangladesh']
yield_2000to2007bd=yield_2000to2007bd.groupby('Year')[['ton/ha_yield','pesticides_tonnes']].sum()
However, the distribution ascended in some of the previous years (2000 to 2007)¶
In [18]:
fig=px.bar(yield_2000to2007bd,y='pesticides_tonnes',
x=yield_2000to2007bd.index,
title='Pesticides usage from 2000 to 2007 in BD',
color='ton/ha_yield'
)
fig.update_layout(
yaxis_title='Pesticides dose (Tonnes)',
xaxis_title='Year',
width=1200,
height=600
)
Some Basic analysis¶
Top ten maize Producing Countries in 2013¶
In [19]:
crop_count=yield_df.groupby('Area')['ton/ha_yield'].sum()
maize_df=yield_df[yield_df.Item=='Maize'][['Area','Year','Item','ton/ha_yield']].sort_values(by='ton/ha_yield',ascending=False)
maize_df_13=maize_df[maize_df.Year==2013]
top_ten_maize_df_13=maize_df_13.groupby('Area')['ton/ha_yield'].sum().sort_values(ascending=False).head(10)
In [20]:
fig=px.bar(
top_ten_maize_df_13,
x=top_ten_maize_df_13.index,
y=top_ten_maize_df_13,
title='Top ten Maize producing countries in 2013',
color=top_ten_maize_df_13.index
)
fig.update_layout(
xaxis_title='Country',
yaxis_title='Yield (Tonne/Ha)',
width=1200,
height=600
)
fig.show()
Top ten Rice Producing Countries in 2013¶
In [21]:
rice_df=yield_df[yield_df.Item=='Rice, paddy']
rice_df=rice_df[rice_df.Year==2013]
rice_df
top_ten_rice_df_13=rice_df.groupby('Area')['ton/ha_yield'].sum()
top_ten_rice_df_13=top_ten_rice_df_13.sort_values(ascending=False)
top_ten_rice_df_13=top_ten_rice_df_13.head(10)
In [22]:
fig=px.bar(
top_ten_rice_df_13,
x=top_ten_rice_df_13.index,
y=top_ten_rice_df_13,
title='Top ten Rice producing countries in 2013',
color=top_ten_rice_df_13.index
)
fig.update_layout(
xaxis_title='Country',
yaxis_title='Yield (Tonne/Ha)',
width=1200,
height=600
)
fig.show()
Ten highest crops (Maize, Potatoes, Rice, Sorghum, Soybeans, Wheat, Cassava, Sweet potatoes, Plantains and others, Yams) yielding countries from 1990 to 2013¶
In [23]:
highest_crops_yield=yield_df.groupby('Area')['ton/ha_yield'].sum()
highest_crops_yield=highest_crops_yield.sort_values(ascending=False)
ten_highest_crops_yield=highest_crops_yield.head(10)
In [24]:
fig=px.bar(
ten_highest_crops_yield,
x=ten_highest_crops_yield.index,
y=ten_highest_crops_yield,
title='Ten highest crop yielding Countries (1990 to 2013)',
color=ten_highest_crops_yield.index
)
fig.update_layout(
xaxis_title='Country',
yaxis_title='Yield (Tonne/Ha)',
width=1200,
height=600
)
fig.show()